package com.lyy.mapper;

import com.lyy.entity.Banner;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Liangyaoyun
 */
@Repository
public interface BannerMapper {
    /**
     * 按条件查询全部轮播图记录
     *
     * @param condition 查询条件
     * @return 查询失败时返回空List对象，结果集按 banner_index 升序，banner_index 相同时按创建时间降序
     */
    @Select("<script> " +
            "select b.banner_id, b.banner_url, b.banner_index, b.create_time, b.modify_time " +
            "from lesson.banner b " +
            "<where> " +
            "<if test='bannerId != null'>and banner_id = #{bannerId}</if> " +
            "<if test='bannerUrl != null'>and banner_url = #{bannerUrl}</if> " +
            "<if test='bannerIndex != null'>and banner_index = #{bannerIndex}</if> " +
            "<if test='createTime != null'>and create_time = #{createTime}</if> " +
            "<if test='modifyTime != null'>and modify_time = #{modifyTime}</if> " +
            "</where> " +
            "order by b.banner_index, b.create_time desc " +
            "</script> ")
    List<Banner> select(Banner condition);



/*    *//**
     * 查询Banner记录
     * @param banner 轮播图实体
     *
     * @return 前5条Banner记录，结果集按 `banner_index` 升序
     *//*
    @Select("<script>" +
            "select b.banner_id, b.banner_url, b.banner_index, b.create_time, b.modify_time " +
            "from lesson.banner b" +
            "<where>" +
            "<if test='bannerId != null'>and banner_id = #{bannerId}</if>" +
            "<if test='bannerUrl != null'>and banner_url = #{bannerUrl}</if>" +
            "<if test='bannerIndex != null'>and banner_index = #{bannerIndex}</if>" +
            "<if test='createTime != null'>and create_time = #{createTime}</if>" +
            "<if test='modifyTime != null'>and modify_time = #{modifyTime}</if>" +
            "</where>" +
            "order by b.banner_index limit 5" +
            "</script>")
    List<Banner> select(Banner banner);
    *//*根据bannerIndex升序查询banner信息*//*
    @Select("select * from lesson.banner order by banner_index limit 5")
    List<Banner> listTop5();

    *//*添加Banner*//*
    @Insert("insert into lesson.banner(banner_url,banner_index,create_time,modify_time)" +
            "value(#{bannerUrl},#{bannerIndex},#{createTime},#{modifyTime})")
    @Options(useGeneratedKeys = true, keyProperty = "bannerId")
    int insertBanner(Banner banner);
    *//*删除Banner*//*
    @Delete("delete from lesson.banner where banner_id=#{bannerId}")
    int deleteByBannerId(Integer bannerId);
    *//*修改语句*//*
    String updateBanner = "<script> update lesson.banner <set> "
            + "<if test='bannerUrl!=null'>banner_url=#{bannerUrl},</if>"
            + "<if test='bannerIndex!=null'>banner_index=#{bannerIndex},</if>"
            + "<if test='modifyTime!=null'>modify_time=#{modifyTime},</if>"
            + "</set>"
            + "where banner_id=#{bannerId}" + "</script>";
    *//*修改Banner*//*
    @Update(updateBanner)
    int updateByBannerId(Banner banner);
    *//*根据主键查询Banner*//*
    @Select("select * from lesson.banner where banner_id=#{bannerId}")
    Banner selectByBannerId(Integer bannerId);*/
}
